package com.gec.dao;

import com.gec.entity.SysUser;
import com.gec.util.DBUtil;

import java.sql.ResultSet;
import java.util.List;

public class SysUserDao extends DBUtil <SysUser> {

    @Override
    public SysUser getEntity(ResultSet rs) throws Exception {
        SysUser sysUser = new SysUser();
        sysUser.setId(rs.getInt("id"));
        sysUser.setAddress(rs.getString("address"));
        sysUser.setUsername(rs.getString("username"));
        sysUser.setPhone(rs.getString("Phone"));
        sysUser.setPassword(rs.getString("Password"));
        return sysUser;
    }

    public SysUser login(String username, String password) {
        String sql = "select * from sys_user where username = ? and password = ?";
        SysUserDao sysUserDao = new SysUserDao();
        List<SysUser> list = sysUserDao.query(sql, username, password);
        if (list.size() <= 0) {
            return null;
        }
        return list.get(0);
    }
}
